using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using KS.Gantt;
using KS.Gantt.Dialogs.Controls;

namespace MiGuava
{
    public partial class ucGroups : ucGridView
    {
        public ucGroups()
        {
            InitializeComponent();

            GRD.AutoGenerateColumns = false;
            GRD.AllowUserToAddRows = false;
            GRD.AllowUserToResizeRows = false;
        }

        public override void InitData()
        {
            GRD.Columns.Clear();

            this.DataSource = m_GanttControl.Groups;                        

            // SetUp custom edit controls            

            // Text
            DataGridViewTextBoxColumn txtText = new DataGridViewTextBoxColumn();
            txtText.DataPropertyName = "Text";
            txtText.HeaderText = "Text";            
            txtText.Width = 240;
            GRD.Columns.Add(txtText);            

            // Duration
            DataGridViewTextBoxColumn txtDuration = new DataGridViewTextBoxColumn();
            txtDuration.DataPropertyName = "DurationForDisplay";
            txtDuration.HeaderText = Properties.Resources.ColumnHeader_Duration;            
            txtDuration.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            txtDuration.Width = 80;
            GRD.Columns.Add(txtDuration);
            
            // StartDate
            DataGridViewTextBoxColumn txtStartDate = new DataGridViewTextBoxColumn();
            txtStartDate.DataPropertyName = "StartDate";
            txtStartDate.HeaderText = Properties.Resources.ColumnHeader_StartDate;
            txtStartDate.ReadOnly = true;            
            txtStartDate.DefaultCellStyle.DataSourceNullValue = DateTime.MaxValue;
            txtStartDate.Width = 120;
            GRD.Columns.Add(txtStartDate);

            // EndDate
            DataGridViewTextBoxColumn txtEndDate = new DataGridViewTextBoxColumn();
            txtEndDate.DataPropertyName = "EndDate";
            txtEndDate.HeaderText = Properties.Resources.ColumnHeader_EndDate;
            txtEndDate.ReadOnly = true;
            txtEndDate.Width = 120;
            GRD.Columns.Add(txtEndDate);
            
            // Description
            DataGridViewTextBoxColumn txtDescription = new DataGridViewTextBoxColumn();
            txtDescription.DataPropertyName = "Description";
            txtDescription.HeaderText = Properties.Resources.ColumnHeader_Description;
            txtDescription.Width = 240;
            GRD.Columns.Add(txtDescription);

            EnableControls();
        }

        protected override void mnuNew_Click(object sender, EventArgs e)
        {
            base.mnuNew_Click(sender, e);

            if (m_GanttControl == null)
                return;

            Program.CursorWait();
            KS.Gantt.Dialogs.GroupEditDialog Dlg = new KS.Gantt.Dialogs.GroupEditDialog();
            Dlg.Edit(m_GanttControl, null);
            Dlg.ShowDialog(this);
            Dlg.Dispose();
            Dlg = null;
        }

        protected override void mnuEdit_Click(object sender, EventArgs e)
        {
            base.mnuEdit_Click(sender, e);

            if (m_GanttControl == null || GRD.CurrentRow == null)
                return;

            GanttItem item = (GanttItem)GRD.CurrentRow.DataBoundItem;
            Program.CursorWait();
            m_GanttControl.EditItem(item);

            SelectGanttItem(item);
        }
    }
}
